home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / optivc16 / vdemow.cpp < prev    next >
C/C++ Source or Header  |  1999-03-06  |  15KB  |  343 lines

  1. /***********************   VDEMOW.CPP  ***********************************
  2. *                                                                        *
  3. *                Demo program for                                        *
  4. *                  O p t i V e c                                         *
  5. *          with Borland C++ 4.x, 5.x, C++ Builder,                       *
  6. *           or Microsoft Visual C++ 5.0 or 6.0                           *
  7. *                                                                        *
  8. *       Copyright 1996-1999 by Martin Sander                             *
  9. *                                                                        *
  10. *                                                                        *
  11. *       This sample program is meant to demonstrate how to use           *
  12. *       OptiVec within your Windows programs. It is not intended         *
  13. *       to demonstrate best Windows programming.                         *
  14. *                                                                        *
  15. **************************************************************************/
  16. /*
  17. Borland C++, Command-line:
  18.     a) 32-bit: type
  19.                BCC32 -W vdemow.cpp vcf3w.lib
  20.     b) 16-bit: type
  21.                BCC -ml -W vdemow.cpp vcl3w.lib
  22. Borland C++, IDE:
  23.     1. Open the new-project menu with  Project/New.
  24.     2. Create a project VDEMOW in the OptiVec directory,
  25.        e.g., \bc\optivec.
  26.     3.a) 32-bit: Choose Application[EXE] for Win32 GUI, static linking,
  27.                  single-thread.
  28.     3.b) 16-bit: Choose Application[EXE] for Windows3.x, memory model LARGE.
  29.     4. Hit OK.
  30.     5. In the Project window that will now be on the screen, delete the
  31.        nodes VDEMOW.DEF and VDEMOW.RC.
  32.     6.a) 32-bit: Add the node VCF3W.LIB.
  33.     6.b) 16-bit: Add the node VCL3W.LIB.
  34.     7. In Options/Project, be sure the include-file search path and the
  35.        library search path both include the respective  OPTIVEC directories,
  36.        e.g.: \bc\optivec\include and bc\optivec\lib, resprectively
  37.     8. Compile and run.
  38. Microsoft Visual C++:
  39.     1. Create a new project as a "Win32 application".
  40.     2. In the project settings, C/C++, Code Generation,
  41.        verify that single-thread debug is chosen.
  42.     3. Add \OptiVec\include to the include-file search path.
  43.     4. Add the files  VDEMOW.CPP  and  OVVCSD.LIB to your project.
  44.     5. Compile and run.
  45. */
  46.  
  47. #include <windows.h>                    /* Compiler's include files */
  48. #include <stdio.h>
  49. #include <math.h>
  50. #include <string.h>
  51. #if defined __FLAT__ || defined _WIN32
  52.     #include <winbase.h>
  53. #else
  54.     #include <dos.h>
  55. #endif
  56.  
  57. #include <VFstd.h>                      /* OptiVec include files */
  58. #include <VCFstd.h>
  59. #include <VFmath.h>
  60. #include <VCFmath.h>
  61. #include <VIstd.h>
  62. #include <Vgraph.h>
  63. #ifndef M_PI
  64.     #define M_PI  3.14159265358979323846
  65. #endif
  66. HWND     hWndMain;
  67. fVector  X1, X2, Y1, Y2, Y3, Y4, Spc, Freq, Win;
  68. cfVector CX1, CX2;
  69. iVector  I1;
  70. ui       vsize, spcsize;
  71. int      vview;
  72. #if defined __FLAT__ || defined WIN32 || defined _WIN32
  73.    struct _SYSTEMTIME tStart, tStop;
  74. #else
  75.     struct   time tStart, tStop;
  76. #endif
  77. NEWMATHERR
  78.  
  79. LONG FAR PASCAL MainMessageHandler (HWND, UINT, WPARAM, LPARAM);
  80.  
  81. void StartTime( void )
  82. {
  83. #if defined __FLAT__ || defined WIN32 || defined _WIN32
  84.     GetLocalTime( &tStart );
  85. #else
  86.     gettime( &tStart );
  87. #endif
  88. }
  89.  
  90. double StopTime( void )
  91. {
  92.    double   tBegin, tEnd;
  93. #if defined __FLAT__ || defined WIN32 || defined _WIN32
  94.     GetLocalTime( &tStop );
  95.     tBegin = (tStart.wHour * 60 + tStart.wMinute) * 60L
  96.             + tStart.wSecond + tStart.wMilliseconds * 0.001;
  97.     tEnd   = (tStop.wHour * 60 + tStop.wMinute) * 60L
  98.             + tStop.wSecond + tStop.wMilliseconds * 0.001;
  99. #else
  100.    gettime( &tStop );
  101.    tBegin = (tStart.ti_hour * 60 + tStart.ti_min) * 60L
  102.             + tStart.ti_sec + tStart.ti_hund * 0.01;
  103.    tEnd   = (tStop.ti_hour * 60 + tStop.ti_min)  * 60L
  104.             + tStop.ti_sec + tStop.ti_hund * 0.01;
  105. #endif
  106.    return( tEnd - tBegin );
  107. }
  108.  
  109.  
  110. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  111.                    LPSTR /* lpCmdLine */, int /* nCmdShow */)
  112. {
  113.     MSG       msg;                      /* MSG structure to pass to windows proc */
  114.     WNDCLASS  wc;
  115.     char      *AppName;                 /* Name for the window */
  116.  
  117.     AppName = "VDemoW";                 /* The name of this application */
  118.     if(!hPrevInstance)
  119.     {
  120.         wc.style      = CS_HREDRAW | CS_VREDRAW;
  121.         wc.lpfnWndProc= MainMessageHandler;
  122.         wc.cbClsExtra = 0;
  123.         wc.cbWndExtra = 0;
  124.         wc.hInstance  = hInstance;
  125.         wc.hIcon      = LoadIcon (hInstance, AppName);
  126.         wc.hCursor    = LoadCursor (NULL, IDC_ARROW);
  127.         wc.hbrBackground  = (HBRUSH) GetStockObject (WHITE_BRUSH);
  128.         wc.lpszMenuName   = AppName;
  129.         wc.lpszClassName  = AppName;
  130.         RegisterClass (&wc);
  131.     }
  132.                              /* create application's Main window:  */
  133.     hWndMain = CreateWindow (AppName,
  134.                              "OptiVec Demo",
  135.                              WS_OVERLAPPEDWINDOW,
  136.                              CW_USEDEFAULT,     /* Use default X, Y, and width  */
  137.                              CW_USEDEFAULT,
  138.                              CW_USEDEFAULT,
  139.                              CW_USEDEFAULT,
  140.                              NULL,              /* Parent window's handle      */
  141.                              NULL,              /* Default to Class Menu       */
  142.                              hInstance,         /* Instance of window          */
  143.                              NULL);             /* Create struct for WM_CREATE */
  144.  
  145.  
  146.     if (hWndMain == NULL)
  147.     {
  148.         MessageBox(NULL, "Could not create window in WinMain", NULL, MB_ICONEXCLAMATION);
  149.         return (1);
  150.     }
  151.  
  152.     ShowWindow(hWndMain, SW_SHOWMAXIMIZED);     /* Display main window      */
  153.     UpdateWindow(hWndMain);
  154.  
  155.     while(GetMessage(&msg, NULL, 0, 0)) /* Main message loop */
  156.     {
  157.         TranslateMessage(&msg);
  158.         DispatchMessage(&msg);
  159.     }
  160.  
  161.     UnregisterClass (AppName, hInstance);
  162.     return (msg.wParam);
  163. }
  164.  
  165. LONG FAR PASCAL
  166. MainMessageHandler(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
  167. {
  168.     HDC         vDC;
  169.     PAINTSTRUCT ps;
  170.  
  171.     char      TimeMsg[100];
  172.     unsigned  i, j;
  173.     float     xt, A=1.2f, B=-0.13f, C=0.85f;
  174.  
  175.  
  176.     switch (Message)                    /* Windows Message Loop           */
  177.     {
  178.         case WM_CREATE:
  179.             vsize  = 1025;
  180.             spcsize = 128;
  181.             vview  =    0;
  182.             I1 = VI_vector( vsize );
  183.             X1 = VF_vector( vsize );
  184.             X2 = VF_vector( vsize );
  185.             Y1 = VF_vector( vsize );
  186.             Y2 = VF_vector( vsize );
  187.             Y3 = VF_vector( vsize );
  188.             Y4 = VF_vector( vsize );
  189.             Spc= VF_vector( spcsize+1 );
  190.             Freq=VF_vector( spcsize+1 );
  191.             Win= VF_vector( 2*spcsize );
  192.             CX1 = VCF_vector( vsize );
  193.             CX2 = VCF_vector( vsize );
  194.             break;
  195.  
  196.         case WM_PAINT:
  197.             vDC = BeginPaint(hWndMain, &ps);
  198.             V_initPlot( hWndMain, vDC );
  199.             switch( vview )
  200.             {
  201.                 default: break;
  202.                 case 0:
  203.                   TextOut( vDC, 10, 10,
  204.                   "This is a series of graphs illustrating VectorLib functions.", 60 );
  205.                   TextOut( vDC, 10, 40,
  206.                   "Always press the right mouse button to see the next view!", 56 );
  207.                   TextOut( vDC, 10, 70,
  208.                   "Press [Alt] [F4] to end the demonstration.", 41 );
  209.                break;
  210.                case 1:
  211.                   TextOut( vDC, 0, 10, "Sine wave", 9 );
  212.                   V_drawAxes( VF_min( X1, vsize/2 ), VF_max( X1, vsize/2 ),
  213.                               -1.0, +1.0 );
  214.                   VF_xyDataPlot( X1, Y1, vsize/2, PS_SOLID, LIGHTRED );
  215.                              // show only half of all waves
  216.                break;
  217.                case 2:
  218.